import jwt from 'jsonwebtoken';
import { jwtconfig, unlesspath } from '../config/app.config';

export function sign(payload: any) {
  return jwt.sign(payload, jwtconfig.secret, {
    expiresIn: jwtconfig.expiresIn
  });
}

export function verfiy(token: string) {
  return jwt.verify(token.split(' ')[1], jwtconfig.secret);
}

export function unless(path: string) {
  return unlesspath.some(function (p) {
    return (typeof p === 'string' && p === path) || (p instanceof RegExp && !!p.exec(path));
  });
}
